const { ListToNode, NodeToList, ListNode, timeL } = require("../utils.js");
/**
 * @param {number} n
 * @return {number[][]}
 */
var generateMatrix = function (n) {
  const list = new Array(n).fill(0);
  let arr = [];
  for (let i = 0; i < n; i++) {
    arr.push([...list]);
  }
  let leng = 2 * n - 1,
    n2 = 0;
  for (let i = 0; i < leng; i++) {
    let y = Math.floor(i / 4);
    switch (i % 4) {
      case 0:
        arr[y] = arr[y].map((item) => {
          return item || ++n2;
        });
        break;
      case 1:
        for (let z = 0; z < n; z++) {
          arr[z][n - y - 1] = arr[z][n - y - 1] || ++n2;
        }
        break;
      case 2:
        for (let z = n - 1; z >= 0; z--) {
          arr[n - y - 1][z] = arr[n - y - 1][z] || ++n2;
        }
        break;
      case 3:
        for (let z = n - 1; z >= 0; z--) {
          arr[z][y] = arr[z][y] || ++n2;
        }
        break;
    }
  }
  return arr;
};
let n = 3;
timeL(generateMatrix, [n]);
